package com.byit.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.byit.config.MinioConfig;
import com.byit.domain.SysAppVersion;
import com.byit.mapper.SysAppVersionMapper;
import com.byit.service.ISysAppVersionService;
import com.byit.utils.PageUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @ClassName SysAppVersionServiceImpl
 * @Description TODO
 * @Author lxp
 * @Date 2019-01-07 15:41
 **/
@Service
public class SysAppVersionServiceImpl extends ServiceImpl<SysAppVersionMapper, SysAppVersion> implements ISysAppVersionService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private SysAppVersionMapper sysAppVersionMapper;


    @Autowired
    private MinioConfig minioConfig;

    @Override
    public void delSysAppVersionById(Map<String, Object> params) {
        sysAppVersionMapper.delSysAppVersionById(params);
    }

    @Override
    public Page<JSONObject> selectSysAppVersionAll(Page<SysAppVersion> pageInfo, Map<String, Object> params) {
        List<JSONObject> list = sysAppVersionMapper.selectSysAppVersionAll(pageInfo, params);


        Page<JSONObject> page = PageUtil.transform(pageInfo);

        page.setRecords(list);

        return page;
    }

    @Override
    public List<JSONObject> selectSysAppVersionList(Map<String, Object> params) {

        List<JSONObject> list = sysAppVersionMapper.selectAppLatestVersion( params);
        list.forEach(info->{
            String dPath = minioConfig.getSearchMinio()+info.getString("dPath");
            list.get(0).put("dPath",dPath);
        });
        return list;
    }
}